package com.example.lib.utils.net

import android.content.Context
import android.net.ConnectivityManager
import android.net.NetworkCapabilities
import com.example.lib.LibApp

object NetStateUtils {

    /**
     * 当前网络是否连接
     */
    fun isNetworkConnected(): Boolean {
        val mConnectivityManager =
            LibApp.appContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager?
        val networkCapabilities = mConnectivityManager?.getNetworkCapabilities(mConnectivityManager.activeNetwork)
        return networkCapabilities?.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED) ?: false
    }

}